﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Zidan : MonoBehaviour
{
    public AudioClip baoza; // 岩石爆炸的音效
    GameObject player; // 飞机
    // Start is called before the first frame update
    void Start()
    {
        player = GameObject.Find("Player"); // 得到场景中的，叫Player的飞机对象    
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(0, 0.1f, 0); // 子弹移动
        if(transform.position.y > 5) // 超出屏幕
        {
            Destroy(this.gameObject); // 销毁子弹
        }
    }
    // 两者刚接触
    private void OnTriggerEnter2D(Collider2D collision)
    {
        /* collision 碰撞到的对象 */
        if(collision.tag == "diren")  // 碰到的对象的标签tag是diren时
        {
            Data.score += 100; // 得分++
            player.GetComponent<AudioSource>().PlayOneShot(baoza); // 让场景中的飞机，播放岩石的爆炸音效
            Destroy(collision.gameObject); // 销毁碰到的对象
            Destroy(this.gameObject); // 销毁子弹
        }
        
    }
}
